<?php

/**
 *
 */
class M_employee extends CI_Model {

  public function __construct() {
    parent::__construct();
    $this->load->database();
  }
  public function getEmployeeList($count,$offset){
    $sql = ' select * from employees order by emid limit '.$offset.','.$count;
    $query = $this->db->query($sql);
    $total = $this->db->query('select * from employees');
    return array(
      'employeelist' => $query->result_array(),
      'total'    => $total->num_rows(),
      'totallist'=> $total->result_array()
    );
  }
  /**
  *添加员工
  */
  public function addEmployee($employee) {
    $sql='insert into employees(emname,embrand,emtel,emposition,emintime,emaddr,embirth,password)'.
    'values("'.$employee['emname'].'","'.$employee['embrand'].'","'.$employee['emtel'].'","'.$employee['emposition'].'","'.$employee['emintime'].
    '","'.$employee['emaddr'].'","'.$employee['embirth'].'","zxc123")';
    return $this->db->simple_query($sql);
  }
  public function updateEmployee($emid,$option){
    if(!$emid || !$option)return false;
    $sql = ' update employees set emname="'.$option['emname'].
    '",embrand="'.$option['embrand'].
    '",emtel="'.$option['emtel'].
    '",emposition="'.$option['emposition'].
    '",emintime="'.$option['emintime'].
    '",embirth="'.$option['embirth'].
    '",emaddr="'.$option['emaddr'].
    '" where emid='.$emid;
    return $this->db->simple_query($sql);
  }
  public function getallemployeeselect(){
    $sql = 'select emid,emname from employees';
    return $this->db->query($sql)->result_array();
  }
  public function getallemployee($count,$offset){
    // $sql = 'select * from employee';
    $sql = 'select * from employees limit '.$offset.','.$count;
    $total = $this->db->query('select * from employees');
    return array(
      'emlist' => $this->db->query($sql)->result_array(),
      'total'    => $total->num_rows()
    );
  }
  public function selectEmployee($selectkey,$count,$offset){
    $sql = ' select * from employees ';
    $selectkey = '"%'.$selectkey.'%"';
    $sql = $sql."where ".
    'emname like '.$selectkey.' or '.
    'emid like '.$selectkey.' or '.
    'emposition like '.$selectkey.' or '.
    'emtel like '.$selectkey.' or '.
    'embirth like '.$selectkey.' or '.
    'embrand like '.$selectkey.' or '.
    'emaddr like '.$selectkey.' or '.
    'emintime like '.$selectkey.
    ' order by emid ';
    $total = $this->db->query($sql);
    $sql = $sql.'limit '.$offset.','.$count;
    $query = $this->db->query($sql);
    return array(
      'employeelist'  => $query->result_array(),
      'total'         => $total->num_rows(),
      'totallist'     => $total->result_array()
    );
  }
  public function resetpass($emid){
    $sql = 'update employees set password="zxc123" where emid='.$emid;
    return $this->db->simple_query($sql);
  }
}


 ?>
